' DOS Doors Program Compiler
' Created 2012-2014 DOS Doors Team (http://dosdoors.net)
Declare Function LetSpecial(strTest As String) As String


Dim As String Header, JumpTable, Program
Dim As Integer TotalRoutines
Dim As String tempString, fileInput, fileOutput, tempStringCommand, tempStringCommand2
Dim As String tempString2, tempString3, tempString4, tempString5, tempString6, tempString7, tempString8
Common Shared returnString1 As String, returnString2 As String
Dim As Integer fileNumInput, fileNumOutput, counter
Dim As UInteger tempInt, tempInt2, tempInt3, tempInt4, tempInt5
Dim As UByte IsString

Header = "DES1"         ' Magic Code

' Version of file
Header = Header & Chr(1)

Print "DOS Doors Compiler."
Input "Enter input filename: ", fileInput
Input "Enter output filename: ", fileOutput

'fileInput = "about.dsf"
'fileOutput = "about.des"

Print "Version Info (Major.Minor.Build):"
Input "Enter major: ", tempInt
If tempInt > 255 then tempInt = 255
Header = Header & Chr(tempInt)
Input "Enter minor: ", tempInt
If tempInt > 255 then tempInt = 255
Header = Header & Chr(tempInt)
Input "Enter build: ", tempInt
If tempInt > 255 then tempInt = 255
Header = Header & Chr(tempInt)

Line Input "Enter programmer name: ", tempString
If Len(tempString) > 255 Then tempString = Left(tempString, 255)
Header = Header & Chr(Len(tempString)) & tempString

Line Input "Enter support e-mail address or website: ", tempString
If Len(tempString) > 255 Then tempString = Left(tempString, 255)
Header = Header & Chr(Len(tempString)) & tempString

tempString = Date
Header = Header & Chr(Len(tempString)) & tempString

fileNumInput = FreeFile

Open fileInput For Input As #fileNumInput
        fileNumOutput = FreeFile
        Open fileOutput for Output As #fileNumOutput
                Print #fileNumOutput, Header;

                Do Until EOF(fileNumInput)
                        counter = counter + 1

                        ' Read the next line of input
                        Line Input #fileNumInput, tempString
                        tempString = Trim(tempString, Any " " + Chr(9))

                        If Len(tempString) > 0 Then
                                If Left(tempString, 1) = "'" Then
                                ElseIf LCase(tempString) = "doevents" Then
                                        Program = Program & "ad"
                                ElseIf LCase(tempString) = "lockwindow" Then
                                        Program = Program & "bha"
                                ElseIf LCase(tempString) = "unlockwindow" Then
                                        Program = Program & "bhb"
                                Else
                                        tempStringCommand = Left(tempString, InStr(tempString, " "))
                                        'Print #fileNumOutput, tempStringCommand

                                        ' Get the actual command from the line
                                        tempStringCommand = LCase(tempStringCommand)
                                        tempStringCommand2 = ""

                                        ' And everything else
                                        If Len(tempString) > Len(tempStringCommand) Then
                                                tempStringCommand2 = LTrim(Mid(tempString, Len(tempStringCommand)))
                                        End If

                                        tempStringCommand = Trim(tempStringCommand)

                                        Select Case tempStringCommand
                                                Case "readkeyboard"
                                                        tempString2 = tempStringCommand2
                                                        tempString3 = Left(tempString2, (InStr(tempString2, ",") - 1))
                                                        tempString2 = Trim(Mid(tempString2, Len(tempString3) + 2))
                                                        tempString2 = Trim(tempString2)
                                                        tempString3 = Trim(tempString3)
                                                        If Len(tempString2) > 0 And Len(tempString3) > 0 Then
                                                        Else
                                                                Print "Parse Error: Expected ',' in READKEYBOARD Statement:"
                                                                Print "["; counter; "] " & tempString
                                                                Exit Do
                                                        End If

                                                        tempString3 = Trim(tempString3)
                                                        ' Put the opcode & variable name
                                                        Program = Program & "dg" & Chr(Len(tempString3)) & tempString3
                                                        ' And the contents
                                                        Program = Program & Chr(Len(tempString2)) & tempString2
                                                Case "pencolor2"
													tempString2 = tempStringCommand2
													tempString2 = Trim(tempString2)

													If Len(tempString2) > 0 Then
													Else
														Print "Parse Error: Expected 'variable name' in PENCOLOR2 Statement:"
														Print "["; counter; "] " & tempString
														Exit Do
													End If

													' Put the opcode & variable name
													Program = Program & "bk" & Chr(Len(tempString2)) & tempString2
												Case "runprogram"
                                                        tempString2 = tempStringCommand2
														tempString2 = Trim(tempString2)

                                                        If Len(tempString2) > 0 Then
                                                        Else
                                                                Print "Parse Error: Expected 'variable name' in RUNPROGRAM Statement:"
                                                                Print "["; counter; "] " & tempString
                                                                Exit Do
                                                        End If

                                                        ' Put the opcode & variable name
                                                        Program = Program & "ae" & Chr(Len(tempString2)) & tempString2
													Case "line"
                                                        tempInt = 0
                                                        If Len(tempStringCommand2) > 1 Then
                                                                tempInt = InStr(tempStringCommand2, ",")
                                                                tempString7 = Left(tempStringCommand2, tempInt - 1)
                                                                tempStringCommand2 = Mid(tempStringCommand2, tempInt + 1)
                                                                
                                                                tempInt = InStr(tempStringCommand2, ")")
                                                                If tempInt > 0 Then
                                                                        tempString2 = Left(tempStringCommand2, tempInt)
                                                                        tempStringCommand2 = Mid(tempStringCommand2, tempInt + 1)
                                                                        tempInt = InStr(tempStringCommand2, ")")
                                                                        If tempInt > 0 Then
                                                                                tempString3 = Left(tempStringCommand2, tempInt)
                                                                                tempStringCommand2 = Trim(Mid(tempStringCommand2, tempInt + 1))
                                                                                If Len(tempStringCommand2) > 0 Then
                                                                                        If Left(tempStringCommand2, 1) = "," Then
                                                                                                tempString6 = Trim(Mid(tempStringCommand2, 2))
                                                                                                tempInt = 99999
                                                                                        Else
                                                                                                Print "Parse Error: Invalid number of arguments for LINE (Must include ,B or ,BF):"
                                                                                                Print "["; counter; "] " & tempString
                                                                                                Exit Do
                                                                                        End If
                                                                                Else
                                                                                        Print "Parse Error: Invalid number of arguments for LINE:"
                                                                                        Print "["; counter; "] " & tempString
                                                                                        Exit Do
                                                                                End If
                                                                        Else
                                                                                Print "Parse Error: Invalid number of arguments for LINE (2nd set):"
                                                                                Print "["; counter; "] " & tempString
                                                                                Exit Do
                                                                        End If
                                                                Else
                                                                        Print "Parse Error: Invalid number of arguments for LINE (1st set):"
                                                                        Print "["; counter; "] " & tempString
                                                                        Exit Do
                                                                End If
                                                        End If
                                                        If (tempInt = 99999) Then ' All variables passed
                                                                tempString2 = Trim(tempString2)
                                                                tempString3 = Trim(tempString3)
                                                                tempString4 = Trim(tempString4)

                                                                ' Make sure the - is in the line
                                                                If Left(tempString3, 1) = "-" Then
                                                                        tempString4 = Trim(Mid(tempString3, 2))
                                                                        ' Now, make sure both start and end locations are enclosed in ()
                                                                        If Left(tempString2, 1) = "(" AndAlso Right(tempString2, 1) = ")" AndAlso Left(tempString4, 1) = "(" AndAlso Right(tempString4, 1) = ")" Then
                                                                                ' Remove the ()
                                                                                tempString2 = Mid(tempString2, 2)
                                                                                tempString2 = Left(tempString2, Len(tempString2) - 1)
                                                                                tempString4 = Mid(tempString4, 2)
                                                                                tempString4 = Left(tempString4, Len(tempString4) - 1)

                                                                                ' Now, split the X/Y coordinates up via the comma
                                                                                tempInt = InStr(tempString2, ",")
                                                                                tempString3 = Mid(tempString2, tempInt + 1)
                                                                                tempString2 = Left(tempString2, tempInt - 1)

                                                                                tempInt = InStr(tempString4, ",")
                                                                                tempString5 = Mid(tempString4, tempInt + 1)
                                                                                tempString4 = Left(tempString4, tempInt - 1)

                                                                                ' Clean up the variables
                                                                                tempString2 = Trim(tempString2)
                                                                                tempString3 = Trim(tempString3)
                                                                                tempString4 = Trim(tempString4)
                                                                                tempString5 = Trim(tempString5)
                                                                                tempString7 = Trim(tempString7)

                                                                                If LCase(tempString6) = "b" Then ' B
                                                                                        Program = Program & "beb"
                                                                                ElseIf LCase(tempString6) = "bf" Then ' BF
                                                                                        Program = Program & "bea"
                                                                                Else ' A normal Line
                                                                                        Program = Program & "bec"
                                                                                End If
                                                                                
                                                                                Program = Program & Chr(Len(tempString7)) & tempString7
                                                                                Program = Program & Chr(Len(tempString2)) & tempString2
                                                                                Program = Program & Chr(Len(tempString3)) & tempString3
                                                                                Program = Program & Chr(Len(tempString4)) & tempString4
                                                                                Program = Program & Chr(Len(tempString5)) & tempString5
                                                                        Else
                                                                                Print "Parse Error: Invalid number of arguments for LINE (must surround co-ords in ()'s:"
                                                                                Print "["; counter; "] " & tempString
                                                                                Exit Do
                                                                        End If
                                                                Else
                                                                        Print "Parse Error: Invalid number of arguments for LINE (missing a dash):"
                                                                        Print "["; counter; "] " & tempString
                                                                        Exit Do
                                                                End If
                                                        End If

                                                        Print tempString7
                                                        Print tempString2
                                                        Print tempString3
                                                        Print tempString4
                                                        Print tempString5
                                                        Print tempString6
                                                    Case "setdoorproperty"
                                                        If Len(tempStringCommand2) > 1 Then
                                                                If (Left(tempStringCommand2, 1) = "(") AND (Right(tempStringCommand2, 1) = ")") Then
                                                                        tempStringCommand2 = Mid(tempStringCommand2, 2)
                                                                        tempStringCommand2 = Left(tempStringCommand2, Len(tempStringCommand2) - 1)
                                                                        tempStringCommand2 = Trim(tempStringCommand2)

                                                                        tempString3 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString4 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString5 = tempStringCommand2

                                                                        If (Len(tempString3) < 1) OR (Len(tempString4) < 1) OR (Len(tempString5) < 1) Then
                                                                              Print "Parse Error: Invalid number of arguments for SETDOORPROPERTY:"
                                                                              Print "["; counter; "] " & tempString
                                                                              Exit Do
                                                                        Else
                                                                              Program = Program & "b1"
                                                                                Print tempString3
                                                                                Print tempString4
                                                                                Print tempString5

                                                                              'tempString3 = Mid(tempString3, 2, Len(tempString3) - 2)

                                                                              ' Window
                                                                              Program = Program & Chr(Len(tempString3)) & tempString3

                                                                              ' Property Name
                                                                              Program = Program & Chr(Len(tempString4)) & tempString4

                                                                              ' Value
                                                                              Program = Program & Chr(Len(tempString5)) & tempString5
                                                                        End If
                                                                Else
                                                                        Print "Parse Error: SETDOORPROPERTY requires '(' and ')':"
                                                                        Print "["; counter; "] " & tempString
                                                                        Exit Do
                                                                End If
                                                        Else
                                                                Print "Parse Error: SETDOORPROPERTY: Not enough parameters:"
                                                                Print "["; counter; "] " & tempString
                                                                Exit Do
                                                        End If
                                                    Case "setcontrolproperty"
                                                        If Len(tempStringCommand2) > 1 Then
                                                                If (Left(tempStringCommand2, 1) = "(") AND (Right(tempStringCommand2, 1) = ")") Then
                                                                        tempStringCommand2 = Mid(tempStringCommand2, 2)
                                                                        tempStringCommand2 = Left(tempStringCommand2, Len(tempStringCommand2) - 1)
                                                                        tempStringCommand2 = Trim(tempStringCommand2)

                                                                        tempString3 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString4 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString5 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString6 = tempStringCommand2

                                                                        If (Len(tempString3) < 1) OR (Len(tempString4) < 1) OR (Len(tempString5) < 1) OR (Len(tempString6) < 1) Then
                                                                              Print "Parse Error: Invalid number of arguments for SETCONTROLPROPERTY:"
                                                                              Print "["; counter; "] " & tempString
                                                                              Exit Do
                                                                        Else
                                                                              Program = Program & "bj"

                                                                              'tempString3 = Mid(tempString3, 2, Len(tempString3) - 2)

                                                                              ' Window
                                                                              Program = Program & Chr(Len(tempString3)) & tempString3

                                                                              ' Control Name
                                                                              Program = Program & Chr(Len(tempString4)) & tempString4

                                                                              ' Property Name
                                                                              Program = Program & Chr(Len(tempString5)) & tempString5

                                                                              ' Value
                                                                              Program = Program & Chr(Len(tempString6)) & tempString6
                                                                        End If
                                                                Else
                                                                        Print "Parse Error: SETCONTROLPROPERTY requires '(' and ')':"
                                                                        Print "["; counter; "] " & tempString
                                                                        Exit Do
                                                                End If
                                                        Else
                                                                Print "Parse Error: SETCONTROLPROPERTY: Not enough parameters:"
                                                                Print "["; counter; "] " & tempString
                                                                Exit Do
                                                        End If
                                                Case "createcontrol"
                                                        If Len(tempStringCommand2) > 1 Then
                                                                If (Left(tempStringCommand2, 1) = "(") AND (Right(tempStringCommand2, 1) = ")") Then
                                                                        tempStringCommand2 = Mid(tempStringCommand2, 2)
                                                                        tempStringCommand2 = Left(tempStringCommand2, Len(tempStringCommand2) - 1)
                                                                        tempStringCommand2 = Trim(tempStringCommand2)

                                                                        tempString3 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString4 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString5 = tempStringCommand2

                                                                        If (Len(tempString3) < 1) OR (Len(tempString4) < 1) OR (Len(tempString5) < 1) Then
                                                                              Print "Parse Error: Invalid number of arguments for CREATECONTROL:"
                                                                              Print "["; counter; "] " & tempString
                                                                              Exit Do
                                                                        Else
                                                                              Program = Program & "bi"

                                                                              'tempString3 = Mid(tempString3, 2, Len(tempString3) - 2)

                                                                              Program = Program & Chr(Len(tempString3)) & tempString3

                                                                              'Program = Program & Chr(Len(tempString4)) & tempString4
                                                                              'If (Left(tempString4, 1) = Chr(34)) AND (Right(tempString4, 1) = Chr(34)) Then
                                                                              '    tempString4 = Mid(tempString4, 2, Len(tempString4) - 2)
                                                                              'Else
                                                                              '    Print "Parse Error: Second argument in CREATECONTROL must be in quotes (" & Chr(34) & "):"
                                                                              '    Print "["; counter; "] " & tempString
                                                                              '    Exit Do
                                                                              'End If

                                                                              Program = Program & Chr(Len(tempString4)) & tempString4
                                                                              Program = Program & Chr(Val(tempString5))
                                                                        End If
                                                                Else
                                                                        Print "Parse Error: CREATECONTROL requires '(' and ')':"
                                                                        Print "["; counter; "] " & tempString
                                                                        Exit Do
                                                                End If
                                                        Else
                                                                Print "Parse Error: CREATECONTROL: Not enough parameters:"
                                                                Print "["; counter; "] " & tempString
                                                                Exit Do
                                                        End If
                                                Case "createwindow"
                                                        If Len(tempStringCommand2) > 1 Then
                                                                If (Left(tempStringCommand2, 1) = "(") AND (Right(tempStringCommand2, 1) = ")") Then
                                                                        tempStringCommand2 = Mid(tempStringCommand2, 2)
                                                                        tempStringCommand2 = Left(tempStringCommand2, Len(tempStringCommand2) - 1)
                                                                        tempStringCommand2 = Trim(tempStringCommand2)

                                                                        tempString3 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString4 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString5 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString6 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString7 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempString8 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))

                                                                        If (Len(tempString3) < 1) OR (Len(tempString4) < 1) OR (Len(tempString5) < 1) OR (Len(tempString6) < 1) OR (Len(tempString7) < 1) OR (Len(tempString8) < 1) Then
                                                                              Print "Parse Error: Invalid number of arguments for CREATEWINDOW:"
                                                                              Print "["; counter; "] " & tempString
                                                                              Exit Do
                                                                        Else
                                                                              Program = Program & "ba"
                                                                              Program = Program & Chr(Len(tempString3)) & tempString3
                                                                              Program = Program & Chr(Len(tempString4)) & tempString4
                                                                              Program = Program & Chr(Len(tempString5)) & tempString5
                                                                              Program = Program & Chr(Len(tempString6)) & tempString6
                                                                              Program = Program & Chr(Len(tempString7)) & tempString7
                                                                              Program = Program & Chr(Len(tempString8)) & tempString8
                                                                        End If
                                                                Else
                                                                        Print "Parse Error: CREATEWINDOW requires '(' and ')':"
                                                                        Print "["; counter; "] " & tempString
                                                                        Exit Do
                                                                End If
                                                        Else
                                                                Print "Parse Error: CREATEWINDOW: Not enough parameters:"
                                                                Print "["; counter; "] " & tempString
                                                                Exit Do
                                                        End If
                                                Case "destroywindow"
                                                Case "dim"
                                                        If Len(tempStringCommand2) > 11 Then
                                                                tempStringCommand2 = LCase(tempStringCommand2)
                                                                If Left(tempStringCommand2, 11) = "as integer " Then
                                                                        tempString2 = Trim(Mid(tempStringCommand2, 12))
                                                                        Program = Program & "ca" & Chr(Len(tempString2)) & tempString2
                                                                ElseIf Left(tempStringCommand2, 10) = "as string " Then
                                                                        tempString2 = Trim(Mid(tempStringCommand2, 11))
                                                                        Program = Program & "cb" & Chr(Len(tempString2)) & tempString2
                                                                Else
                                                                        Print "Parse Error: Invalid type detected:"
                                                                        Print "["; counter; "] " & tempString
                                                                        Exit Do
                                                                End If
                                                        Else
                                                                Print "Parse Error: Invalid use of DIM:"
                                                                Print "["; counter; "] " & tempString
                                                                Exit Do
                                                        End If
                                                Case "end"
                                                        tempStringCommand2 = LCase(tempStringCommand2)
                                                        Select Case tempStringCommand2
                                                                Case "sub"
                                                                        Program = Program & "ab"
                                                                Case Else
                                                                        Print "Parse Error: Invalid use of END:"
                                                                        Print "["; counter; "] " & tempString
                                                                        Exit Do
                                                        End Select
                                                Case "let"
                                                        tempString2 = tempStringCommand2
                                                        tempString3 = Left(tempString2, InStr(tempString2, " "))
                                                        tempString2 = Trim(Mid(tempString2, Len(tempString3)))
                                                        If Left(tempString2, 2) = "= " Then
                                                                tempString4 = Trim(Mid(tempString2, 2))
                                                                If (Left(tempString4, 1) = Chr(34)) AND (Right(tempString4, 1) = Chr(34)) Then
                                                                        IsString = 1
                                                                        tempString4 = Mid(tempString4, 2)
                                                                        tempString4 = Left(tempString4, Len(tempString4) - 1)
                                                                Else
                                                                    IsString = 0
                                                                End If
                                                        Else
                                                                Print "Parse Error: Expected '=' in LET Statement:"
                                                                Print "["; counter; "] " & tempString
                                                                Exit Do
                                                        End If

                                                        tempString3 = Trim(tempString3)
                                                        
                                                        ' Create a backup copy of the string
                                                        tempString6 = tempString4        

                                                        ' Now see if the contents have any special assignments in it
                                                        tempString5 = LetSpecial(tempString4)
                                                        If (tempString5 = "") OR (IsString = 1) Then
                                                            ' Put the opcode & variable name
                                                            Program = Program & "da" & Chr(Len(tempString3)) & tempString3
                                                            ' And the contents
                                                            Program = Program & Chr(Len(tempString6)) & tempString6
                                                        Else
                                                            If Len(tempString5) > 1 Then
                                                                Print "Parse Error: Only one function allowed in LET Statement:"
                                                                Print "["; counter; "] " & tempString5
                                                                Exit Do
                                                            Else
                                                                Select Case tempString5
                                                                    Case "+"
                                                                        ' Opcode & variable name
                                                                        Program = Program & "db" & Chr(Len(tempString3)) & tempString3
                                                                        ' And the contents for part 1
                                                                        Program = Program & Chr(Len(returnString1)) & returnString1
                                                                        ' And the contents for part 2
                                                                        Program = Program & Chr(Len(returnString2)) & returnString2
                                                                    Case "-"
                                                                        ' Opcode & variable name
                                                                        Program = Program & "dc" & Chr(Len(tempString3)) & tempString3
                                                                        ' And the contents for part 1
                                                                        Program = Program & Chr(Len(returnString1)) & returnString1
                                                                        ' And the contents for part 2
                                                                        Program = Program & Chr(Len(returnString2)) & returnString2
                                                                    Case "*"
                                                                        ' Opcode & variable name
                                                                        Program = Program & "dd" & Chr(Len(tempString3)) & tempString3
                                                                        ' And the contents for part 1
                                                                        Program = Program & Chr(Len(returnString1)) & returnString1
                                                                        ' And the contents for part 2
                                                                        Program = Program & Chr(Len(returnString2)) & returnString2
                                                                    Case "/", "\"
                                                                        ' Opcode & variable name
                                                                        Program = Program & "de" & Chr(Len(tempString3)) & tempString3
                                                                        ' And the contents for part 1
                                                                        Program = Program & Chr(Len(returnString1)) & returnString1
                                                                        ' And the contents for part 2
                                                                        Program = Program & Chr(Len(returnString2)) & returnString2
                                                                    Case "&"    ' String concat
                                                                        ' Opcode & variable name
                                                                        Program = Program & "df" & Chr(Len(tempString3)) & tempString3
                                                                        ' And the contents for part 1
                                                                        Program = Program & Chr(Len(returnString1)) & returnString1
                                                                        ' And the contents for part 2
                                                                        Program = Program & Chr(Len(returnString2)) & returnString2
                                                                End Select
                                                            End If
                                                        End If
                                                Case "printstring"
                                                        If Len(tempStringCommand2) > 1 Then
                                                                If (Left(tempStringCommand2, 1) = "(") AND (Right(tempStringCommand2, 1) = ")") Then
                                                                        tempStringCommand2 = Mid(tempStringCommand2, 2)
                                                                        tempStringCommand2 = Left(tempStringCommand2, Len(tempStringCommand2) - 1)
                                                                        tempStringCommand2 = Trim(tempStringCommand2)

                                                                        tempString3 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString4 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString5 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempString6 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))

                                                                        If (Len(tempString3) < 1) OR (Len(tempString4) < 1) OR (Len(tempString5) < 1) OR (Len(tempString6) < 1) Then
                                                                              Print "Parse Error: Invalid number of arguments for PRINTSTRING:"
                                                                              Print "["; counter; "] " & tempString
                                                                              Exit Do
                                                                        Else
                                                                              Program = Program & "bc"
                                                                              Program = Program & Chr(Len(tempString3)) & tempString3
                                                                              Program = Program & Chr(Len(tempString4)) & tempString4
                                                                              Program = Program & Chr(Len(tempString5)) & tempString5
                                                                              Program = Program & Chr(Len(tempString6)) & tempString6
                                                                        End If
                                                                Else
                                                                        Print "Parse Error: PRINTSTRING requires '(' and ')':"
                                                                        Print "["; counter; "] " & tempString
                                                                        Exit Do
                                                                End If
                                                        Else
                                                                Print "Parse Error: CREATEWINDOW: Not enough parameters:"
                                                                Print "["; counter; "] " & tempString
                                                                Exit Do
                                                        End If
                                                Case "pencolor"
                                                        If Len(tempStringCommand2) > 1 Then
                                                                If (Left(tempStringCommand2, 1) = "(") AND (Right(tempStringCommand2, 1) = ")") Then
                                                                        tempStringCommand2 = Mid(tempStringCommand2, 2)
                                                                        tempStringCommand2 = Left(tempStringCommand2, Len(tempStringCommand2) - 1)
                                                                        tempStringCommand2 = Trim(tempStringCommand2)

                                                                        tempString3 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString4 = Trim(Left(tempStringCommand2, InStr(tempStringCommand2, ",") - 1))
                                                                        tempStringCommand2 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))
                                                                        tempString5 = Trim(Mid(tempStringCommand2, InStr(tempStringCommand2, ",") + 1))

                                                                        Print tempString3
                                                                        Print tempString4
                                                                        Print tempString5
                                                                        If (Len(tempString3) < 1) OR (Len(tempString4) < 1) OR (Len(tempString5) < 1) Then
                                                                              Print "Parse Error: Invalid number of arguments for PENCOLOR :"
                                                                              Print "["; counter; "] " & tempString
                                                                              Exit Do
                                                                        Else
                                                                              Program = Program & "bg"
                                                                              Program = Program & Chr(Len(tempString3)) & tempString3
                                                                              Program = Program & Chr(Len(tempString4)) & tempString4
                                                                              Program = Program & Chr(Len(tempString5)) & tempString5
                                                                        End If
                                                                Else
                                                                        Print "Parse Error: PRINTSTRING requires '(' and ')':"
                                                                        Print "["; counter; "] " & tempString
                                                                        Exit Do
                                                                End If
                                                        Else
                                                                Print "Parse Error: PENCOLOR: Not enough parameters:"
                                                                Print "["; counter; "] " & tempString
                                                                Exit Do
                                                        End If
                                                Case "call"
                                                      If Len(tempStringCommand2) > 0 Then
                                                            tempStringCommand2 = LCase(tempStringCommand2)
                                                            Program = Program & "aa"
                                                            Program = Program & Chr(Len(tempStringCommand2)) & tempStringCommand2
                                                      Else
                                                            Print "Parse Error: Required routine name: CALL <NAME>:"
                                                            Print "["; counter; "] " & tempString
                                                            Exit Do
                                                      End If
                                                Case "sub"
                                                        If Len(tempStringCommand2) > 0 Then
                                                                TotalRoutines = TotalRoutines + 1
                                                                ' Store the subroutine name
                                                                JumpTable = JumpTable & Chr(Len(tempStringCommand2)) & LCase(tempStringCommand2)
                                                                ' Store the actual location in the program
                                                                tempInt = Len(Program)
                                                                tempInt = tempInt + 1

                                                                JumpTable = JumpTable & Chr(Len(Str(tempInt))) & Str(tempInt)
                                                        Else
                                                                Print "Parse Error: No routine name given:"
                                                                Print "["; counter; "] " & tempString
                                                                Exit Do
                                                        End If
                                                Case Else
                                                        Print "Invalid command detected [" & Chr(34) & tempStringCommand & Chr(34) & "]:"
                                                        Print "["; counter; "] " & tempString
                                                        Exit Do
                                        End Select
                                End If
                        End If
                Loop
                Print #fileNumOutput, Chr(TotalRoutines) & JumpTable;
                Print #fileNumOutput, Program;
        Close #fileNumOutput
Close #fileNumInput

' Test to see if "Special" characters/phrases are in a string for "Let" assignment and return what it is
Function LetSpecial(strTest As String) As String
    Dim As String strReturn

    returnString1 = ""
    returnString2 = ""
    strTest = LCase(strTest)
    
    If InStr(strTest, "+") Then
        strReturn = strReturn & "+"
        returnString1 = Left(strTest, InStr(strTest, "+") - 1)
        returnString2 = Mid(strTest, InStr(strTest, "+") + 1)
    ElseIf InStr(strTest, "-") Then
        strReturn = strReturn & "-"
        returnString1 = Left(strTest, InStr(strTest, "-") - 1)
        returnString2 = Mid(strTest, InStr(strTest, "-") + 1)
    ElseIf InStr(strTest, "*") Then
        strReturn = strReturn & "*"
        returnString1 = Left(strTest, InStr(strTest, "*") - 1)
        returnString2 = Mid(strTest, InStr(strTest, "*") + 1)
    ElseIf InStr(strTest, "/") Then
        strReturn = strReturn & "/"
        returnString1 = Left(strTest, InStr(strTest, "/") - 1)
        returnString2 = Mid(strTest, InStr(strTest, "/") + 1)
    ElseIf InStr(strTest, "\") Then
        strReturn = strReturn & "\"
        returnString1 = Left(strTest, InStr(strTest, "\") - 1)
        returnString2 = Mid(strTest, InStr(strTest, "\") + 1)
    Elseif InStr(strTest, "&") Then
        strReturn = strReturn & "&"
        returnString1 = Left(strTest, InStr(strTest, "&") - 1)
        returnString2 = Mid(strTest, InStr(strTest, "&") + 1)
    ElseIf InStr(strTest, "sqrt ") Then
        strReturn = strReturn & "!"
        returnString2 = Mid(strTest, InStr(strTest, "sqrt ") + 1)
    Else
        strReturn = ""
    End If

    ' Clean the variables up
    returnString1 = Trim(returnString1, Any " " + Chr(9))
    returnString2 = Trim(returnString2, Any " " + Chr(9))
    
    Return strReturn
End Function